package com.m2bshop.shop.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.m2bshop.shop.pojo.good_imgs;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface GoodimgDao extends BaseMapper<good_imgs> {
    //商品图片信息
    @Insert("insert into good_imgs (goodid,url,seq) values(#{goodid},#{url},#{seq})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    public int AddPictures(good_imgs img);

    @Delete("delete from good_imgs where id=#{id}")
    public int deletePictures(int id);

    @Update("update good_imgs set goodid=#{goodid},url=#{url},seq=#{seq} where id=#{id}")
    public int updatePictures(good_imgs img);

    @Select("select *,a.id 'pid',b.id 'sid' from good_imgs a,BMCgoods b where a.goodid = b.id and b.id = #{id} ORDER BY seq")
    @Results({
            @Result(id=true,property = "id",column = "pid"),
            @Result(property ="goodid",column = "goodid"),
            @Result(property = "url",column = "url"),
            @Result(property = "seq",column = "seq")
    })
    public List<good_imgs> getAllImgs(int id);
}
